package com.zhoug.common3.screenrecord;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;

import androidx.annotation.DrawableRes;
import androidx.core.app.NotificationCompat;

/**
 * @Author: zhoug
 * @Date: 2024-09-04
 * @Description:
 */
public class SimpleScreenRecordNotification implements IScreenRecordNotification {
    private int notificationId = 865;
    private @DrawableRes int smallIcon;
    private String channelId;
    private String channelName;
    private String channelDescription;

    public SimpleScreenRecordNotification() {
    }

    public void setNotificationId(int id) {
        this.notificationId = id;
    }

    public void setNotificationChannel(String channelId, String channelName, String channelDescription) {
        this.channelId = channelId;
        this.channelName = channelName;
        this.channelDescription = channelDescription;
    }

    public void setSmallIcon(@DrawableRes int smallIcon) {
        this.smallIcon = smallIcon;
    }

    @Override
    public Notification create(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (channelId == null) {
                channelId = context.getPackageName() + "_ScreenRecord";
            }
            if(channelName==null){
                channelName="录屏通知";
            }
            NotificationChannel mChannel = new NotificationChannel(channelId, channelName,
                    NotificationManager.IMPORTANCE_HIGH);//设置为LOW会没有声音 ;MAX：最重要的程度， 会弹出一个单独消息框，让用户做出相应
            mChannel.enableLights(false);//设置闪灯
            mChannel.setDescription(channelDescription);
//            mChannel.setLightColor(Color.RED);//通知灯颜色,前提是该频道上的指示灯已启用,并且设备支持该颜色功能
            mChannel.enableVibration(false);//震动
            //声音
            notificationManager.createNotificationChannel(mChannel);
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId);
        builder.setContentTitle("正在录屏");
        if (smallIcon != 0) {
            builder.setSmallIcon(smallIcon);
        }
        return builder.build();
    }


    @Override
    public int getNotificationId() {
        return notificationId;
    }

}
